package Dao;

import bean.Doctor;
import bean.customer;
import org.omg.CORBA.Object;

import java.util.List;

public class doctorDaoImpl extends BaseDao{
    public List<Doctor> queryDoctors() throws Exception {
        String sql = "SELECT did, account,dname,fee,gender,age,office,room,career,description,ability,picpath FROM doctor";
        return queryForList(Doctor.class,sql);
    }

    public Doctor queryDoctorByName(String name) {
        String sql = "SELECT did, account,dname,fee,gender,age,room,office,career,description,ability,picpath FROM doctor where dname = ?";
        try {
            return queryForOne(Doctor.class,sql,name);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    public Doctor queryDoctorById(Integer id) {
        String sql = "SELECT did, account,dname,fee,gender,age,room,office,career,description,ability,picpath FROM doctor where did = ?";
        try {
            return queryForOne(Doctor.class,sql,id);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    public List<Doctor> queryDoctorsByDepartment(String office ) throws Exception {
        String sql = "SELECT did, account,dname,fee,gender,age,room,office,career,description,ability,picpath FROM doctor WHERE office = ?";
        return queryForList(Doctor.class,sql, office);
    }

    public int addDoctor(Doctor doctor) {
        String sql = "INSERT INTO doctor (dname,fee,gender,age,office,career,description, ability,picpath,room) VALUES(?,?,?,?,?,?,?,?,?,?)";
        try {
            return update(sql,doctor.getDname(),doctor.getFee(),doctor.getGender(),doctor.getAge(),doctor.getOffice(),doctor.getCareer(),doctor.getDescription(),doctor.getAbility(),doctor.getPicpath(),doctor.getRoom());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }



    public int deleteDoctorBYId(Integer id) {
        String sql = "DELETE FROM doctor WHERE did=?";
        try {
            return update(sql,id);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public int updateDoctor(Doctor doctor) {
        String sql = "update doctor set dname = ?, fee = ?,gender =  ?,age=?,office=?,career=?,description=?,ability=?,room=? where did = ? ";
        try {
            return update(sql,doctor.getDname(),doctor.getFee(),doctor.getGender(),doctor.getAge(),doctor.getOffice(),doctor.getCareer(),doctor.getDescription(),doctor.getAbility(),doctor.getRoom(),doctor.getDid());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }






/* create table if not exists doctor (did int primary key auto_increment,
                         account char(16) ,
                         password char(16),
                         dname char(16),
                         fee int comment '医生出诊费',
                         gender char(2),
                         age tinyint,
                         office char(16),
                         room char(16),
                         career char(8),
                         description varchar(255),
                         picpath varchar(64));*/
}
